home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue26 / directx / MINDIRX1.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1997-07-22  |  2.7 KB  |  91 lines

  1. unit MinDirX1;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   DirectX, StdCtrls, ExtCtrls, ComObj;
  8.  
  9. type
  10.  
  11.   TFrmMain = class(TForm)
  12.     Timer1: TTimer;
  13.  
  14.     procedure FormCreate(Sender: TObject);
  15.     procedure Timer1Timer(Sender: TObject);
  16.   public
  17.     D3DRM: IDirect3DRM;
  18.     Scene, Camera, Lights, MyVisualObject: IDirect3DRMFrame;
  19.     MeshBuilder: IDirect3DRMMeshBuilder;
  20.     Light1: IDirect3DRMLight;
  21.     View: IDirect3DRMViewPort;
  22.     DDClipper: IDirectDrawClipper;
  23.   end;
  24.  
  25. var
  26.   frmMain: TfrmMain;
  27.   Dev: IDirect3DRMDevice;
  28.  
  29. implementation
  30.  
  31.  
  32.  
  33. {$R *.DFM}
  34.  
  35. procedure TfrmMain.FormCreate(Sender: TObject);
  36. begin
  37.   // Create the IDirect3DRM interface from
  38.   // which other interfaces are created and managed.
  39.   Direct3DRMCreate(D3DRM);
  40.  
  41.   // Create frames to provide location and velocity for
  42.   // each visual element in the 3D landscape.
  43.   D3DRM.CreateFrame(Nil, Scene);
  44.   D3DRM.CreateFrame(Scene, Lights);
  45.   D3DRM.CreateFrame(Scene, Camera);
  46.   D3DRM.CreateFrame(Scene, MyVisualObject);
  47.  
  48.   // These next steps create an IDirect3DRMDevice that
  49.   // keeps track of hardware/software capabilities,
  50.   // and the window area thatÆs being drawn to.
  51.   DirectDrawCreateClipper(0, DDClipper, Nil);
  52.   DDClipper.SetHWnd(0, Handle);
  53.   D3DRM.CreateDeviceFromClipper(DDClipper, Nil, ClientWidth, ClientHeight, Dev);
  54.  
  55.   // Create a 3D visible object, add it to the scene, 
  56.   // and give it a spin.
  57.   D3DRM.CreateMeshBuilder(MeshBuilder);
  58.   MeshBuilder.Load(PChar('Egg.x'), Nil, D3DRMLOAD_FROMFILE, Nil, Nil);
  59.   MyVisualObject.AddVisual(IDirect3DRMVisual(MeshBuilder));
  60.   MyVisualObject.SetRotation(Scene, 1, 1, 1, 0.01);
  61.  
  62.   // Add a light and attach the light to a frame.
  63.   // Forgetting this step makes for a fully functioning,
  64.   // but extremely boring display.
  65.   D3DRM.CreateLightRGB(D3DRMLIGHT_DIRECTIONAL, 0.03, 0.9, 0.9, Light1);
  66.   Lights.AddLight(Light1);
  67.  
  68.   // The viewport defines how a 3D scene is rendered to a 2D window.
  69.   // The position and orientation of the second parameter (Camera)
  70.   // defines the point-of-view of the user.
  71.   D3DRM.CreateViewPort(Dev, Camera, 0, 0, ClientWidth, ClientHeight,
  72.     View);
  73.   Camera.SetPosition(Scene, 0, 0, -7);
  74.  
  75.   Timer1.Interval := 1;
  76. end;
  77.  
  78. // The Tick method actually encapsulates four other tasks: 
  79. //   IDirect3DRMFrame.Move: Reposition frames according to rotation and //     velocity.
  80. //   IDirect3DRMViewport.Clear: Clear the viewport to the current
  81. //     background color.
  82. //   IDirect3DRMViewport.Render: Draw the 3D scene to memory.
  83. //   IDirect3DRMDevice.Update: Copy the rendered scene to the window.
  84. procedure TfrmMain.Timer1Timer(Sender: TObject);
  85. begin
  86.   D3DRM.Tick(1.0);
  87. end;
  88.  
  89. end.
  90.  
  91.